package javase_class_250902;

/**
 * ClassName: AnimalTest
 * Package: javase_class_250902
 * Description:
 *
 * @Author harkjeans
 * @Create 2025/9/2 17:56
 * @Version 1.0
 */
public class AnimalTest {
    public static void main(String[] args) {

        Animal animal1 = new Animal();

        animal1.name = "老虎";
        animal1.setLeg(2);

        System.out.println(animal1.name + animal1.getLeg());

        animal1.eat();

    }
}

class Animal{
    String name;
    private int leg;//leg在class外不可被调用

    //设置leg属性
    public void setLeg(int l){
        if(l >= 0 && l % 2 == 0){
            leg = l;
        }else{
            System.out.println("你输入的数据非法");
        }
    }

    //获取leg属性
    public int getLeg(){
        return leg;
    }

    public void eat(){
        System.out.println("动物觅食");
    }

}
